package com.vhall.component.plugin.common.aspect;

import org.springframework.beans.factory.annotation.Value;

import javax.servlet.http.HttpServletRequest;

import static com.vhall.component.plugin.common.constant.RoomConstant.MOCK_FLAG;

/**
 * 基础数据处理切面
 *
 * @author shimingming
 * @since 2023/5/9 14:06
 */
public class BaseDataAspect {

    @Value("${spring.profiles.active:''}")
    private String active;

    private static final String TEST_FLAG = "test";
    private static final String DEV_FLAG = "dev";

    /**
     * 判断是否需要使用mock数据
     *
     * @return true 需要使用mock数据;false 不需要
     */
    public boolean validMockFlag(HttpServletRequest request) {

        String vsstoken = request.getHeader("vsstoken");
        String token = request.getParameter("token");
        String headerToken = request.getHeader("token");

        return (TEST_FLAG.equals(active) || DEV_FLAG.equals(active)) &&
                (MOCK_FLAG.equals(vsstoken) || MOCK_FLAG.equals(token) || MOCK_FLAG.equals(headerToken));
    }
}
